# You can set these variables from the command line.

# module_name === project in conf.py, use \_ instead of _ if module name contains _
module_name := BMRuntime
output_file_prefix := BMRuntime

# LANG := zh

# ifeq ($(LANG), en)
#   SOURCEDIR_en     = source_en
#   pdf_name_en      = BMRuntime Development Reference Manual.pdf
# else ifeq ($(LANG), zh)
#   SOURCEDIR_en     = source_zh
#   pdf_name_en      = BMRUNTIME开发参考手册.pdf
# else
#   exit 1
# endif
SOURCEDIR_en     = source_en
pdf_name_en      = BMRuntime Technical Reference Manual.pdf

SOURCEDIR_zh    = source_zh
pdf_name_zh      = BMRUNTIME开发参考手册.pdf

SPHINXOPTS    =
SPHINXBUILD   = sphinx-build
BUILDDIR_en      = build_en
BUILDDIR_zh      = build_zh

# Put it first so that "make" without argument is like "make help".
help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR_en)" "$(BUILDDIR_en)" $(SPHINXOPTS) $(O)
	@$(SPHINXBUILD) -M help "$(SOURCEDIR_zh)" "$(BUILDDIR_zh)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR_en)" "$(BUILDDIR_en)" $(SPHINXOPTS) $(O)
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR_zh)" "$(BUILDDIR_zh)" $(SPHINXOPTS) $(O)

pdf: latex
	@mkdir build -p
	@cd $(BUILDDIR_en)/latex && xelatex $(module_name).tex
	@cd $(BUILDDIR_en)/latex && xelatex $(module_name).tex
	@mv $(BUILDDIR_en)/latex/$(module_name).pdf build/"${pdf_name_en}" && rm -rf $(BUILDDIR_en)/latex

	@cd $(BUILDDIR_zh)/latex && xelatex $(module_name).tex
	@cd $(BUILDDIR_zh)/latex && xelatex $(module_name).tex
	@mv $(BUILDDIR_zh)/latex/$(module_name).pdf build/"${pdf_name_zh}" && rm -rf $(BUILDDIR_zh)/latex

web: html
	#@python3 -m http.server --directory build/html

clean:
	@rm -rf $(BUILDDIR_en)
	@rm -rf $(BUILDDIR_zh)
